package TemplateMethod;

public abstract class AbstractDefiniteIntegral {
    protected abstract double geta();
    protected abstract double getb();
    protected abstract int getc();
    protected abstract double function(double x);

    public final double calDefiniteIntegral()
    {
        double a = 0, b = 0, t = 0,sum = 0;
        int c = 0;
        a = geta();
        b = getb();
        c = getc();

        if(a > b)
        {
            t = a; a = b; b = t;
        }
        t = (b - a)/(double)c;

        for(int i = 0; i < c; ++i)
        {
            sum += t * function(a + i*t);
        }
        return sum;
    }


}
